package thread;

class MyRunnable implements Runnable {
    //线程任务的入口
    @Override
    public void run() {
        while (true) {
            System.out.println("hello runnable");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        //这个使用Runnable来进行Thread的传参构造，来创建线程，并且这个任务是在Thread的外面
        //这个方法呢是降低了藕合
        Runnable runnable = new MyThread();
        Thread t = new Thread(runnable);
        t.start();

        while(true) {
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }
}
